package com.example.base_kotlin_xml.view

import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import com.blankj.utilcode.util.LogUtils
import com.example.base_kotlin_xml.R
import com.example.base_kotlin_xml.databinding.FragmentFlowEventBusBinding
import com.example.base_model.utils.FlowEventBus
import com.example.base_model.view.BaseFragment
import dagger.hilt.android.AndroidEntryPoint

/**
 * @Author: jiangKunKun
 * @CreateDate: 2025/7/30
 * @Description: 事件总线 FlowEventBus
 * @SpittingGrooves
 */
@AndroidEntryPoint
class FlowEventBusFragment : BaseFragment<FragmentFlowEventBusBinding>() {

    override fun initObservers() {
        FlowEventBus.observeStickyEvent<String>(lifecycleScope, "粘性事件"){
            LogUtils.d("粘性事件 接收到来自 MainActivity 的发送", it)
        }
    }

    override fun initClickEvents() {
        // 事件总线1 点击限制
        mBinding.btnFlowEventBus1.setOnClickListener {
            FlowEventBus.postEvent("123","FlowEventBusActivity 发送的数据 666") }
        // 事件总线2 点击限制
        mBinding.btnFlowEventBus2.setOnClickListener {
            FlowEventBus.postEvent("123","FlowEventBusActivity 发送的第二条数据 777") }
        // 事件总线3 点击限制
        mBinding.btnFlowEventBus3.setOnClickListener {
            FlowEventBus.postEvent("123","FlowEventBusActivity 发送的多数据测试 888")
            FlowEventBus.postEvent("123","FlowEventBusActivity 发送的多数据测试 999")
            FlowEventBus.postEvent("123","FlowEventBusActivity 发送的多数据测试 101010") }
        // 返回
        mBinding.btnFlowEventBus4.setOnClickListener {
            findNavController().popBackStack()
        }
    }

    override fun initData() {
    }

    override fun enableBackPress(): Boolean = false

    override fun attachLayoutRes(): Int = R.layout.fragment_flow_event_bus
}